﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;

namespace Projekt_GUI.Forms
{
    public partial class Locations : Form
    {
        public Locations()
        {
            InitializeComponent();

            using (OracleConnection con = new OracleConnection("Data Source=" + Form1.CONFIG_DB_HOST + "; User Id=" + Form1.CONFIG_DB_USER + "; Password=" + Form1.CONFIG_DB_PASS))
            {
                con.Open();
                OracleCommand com = con.CreateCommand();
                com.CommandText = "Select Name FROM Location_Typ";

                OracleDataReader odr = com.ExecuteReader();

                while (odr.Read())
                {
                    comboBox1.Items.Add(odr.GetString(0));
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && comboBox1.SelectedIndex >= 0)
            {
                using (OracleConnection con = new OracleConnection("Data Source=" + Form1.CONFIG_DB_HOST + "; User Id=" + Form1.CONFIG_DB_USER + "; Password=" + Form1.CONFIG_DB_PASS))
                {
                    con.Open();
                    OracleCommand com = con.CreateCommand();
                    com.CommandText = "INSERT INTO Locations VALUES(SQ_Locations.NEXTVAL, '" + comboBox1.SelectedText + "', '" + textBox1.Text + "',  '" + textBox2.Text + "', '" + textBox3.Text + "', '" + textBox4.Text + "', '" + textBox5.Text + "', '" + textBox9.Text + "', '" + textBox6.Text + "', '" + textBox7.Text + "', '" + textBox8.Text + "')";

                    com.ExecuteNonQuery();
                }

                Close();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Locations_Load(object sender, EventArgs e)
        {

        }
    }
}
